//
//  IGScreenModelVC.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/11/17.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGScreenModelVC.h"
#import "IGScreenModelApi.h"


@interface IGScreenModelVC ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) IGEquRemoteModel *model;
@property (nonatomic, strong) IGScreenModelApi *api;

@end

@implementation IGScreenModelVC

- (instancetype)initWithModel:(IGEquRemoteModel *)model
{
    self = [super init];
    if (self)
    {
        self.model = model;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor mainBackgroundColor];
    self.api = [IGScreenModelApi new];
//    self.title = @"屏幕模式";
    self.title = NSLocalizedString(@"Screen Mode", nil);
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}


- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorInset = UIEdgeInsetsMake(0, -100, 0, 0);
    }
    return _tableView;
}

#pragma mark -<UITableViewDelegate, UITableViewDataSource>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self plateChange:[NSString stringWithFormat:@"%ld",indexPath.row]];
}

- (void)plateChange:(NSString *)index
{
    _api.plates = index;
    _api.macId = _model.macId;
    [_api startWithDecodeClass:[IGScreenModelResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject)
        {
            self.model.plates = index;
            [self.tableView reloadData];
        }
    }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"IGScreenModelVCID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    cell.textLabel.font = [UIFont font16];
    cell.textLabel.textColor = [UIColor c4Color];
    UIImageView *acc = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 13, 9)];
    acc.contentMode = UIViewContentModeScaleAspectFit;
    if (indexPath.row == 0)
    {
//        cell.textLabel.text = @"横屏";
        cell.textLabel.text = NSLocalizedString(@"Horizontal screen", nil);
        acc.image = [self.model.plates isEqualToString:@"0"] ? [UIImage imageNamed:@"iGallery_select"] : nil;
        cell.accessoryView = acc;
    }
    else if (indexPath.row == 1)
    {
//        cell.textLabel.text = @"竖屏";
        cell.textLabel.text = NSLocalizedString(@"Vertical screen", nil);
        acc.image = [self.model.plates isEqualToString:@"1"] ? [UIImage imageNamed:@"iGallery_select"] : nil;
        cell.accessoryView = acc;
    }
    return cell;
}



@end
